package com.example.demo.repository;

import com.example.demo.pojo.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.Optional;

public interface UserRepository extends JpaRepository<User, Long> {
    // 根据用户名查询用户
    Optional<User> findByUsername(String username);

    // 根据用户ID查询用户
    Optional<User> findById(Long id);

    // 根据邮箱查询用户
    Optional<User> findByEmail(String email);

    // 检查用户名是否已存在
    boolean existsByUsername(String username);

    // 检查邮箱是否已存在
    boolean existsByEmail(String email);

    // 根据用户名和密码查询用户
    @Query("SELECT u FROM User u WHERE u.username = :username AND u.password = :password")
    Optional<User> findByUsernameAndPassword(@Param("username") String username, @Param("password") String password);


}